<?php
	session_start();
	include('../functions/soap.php');
	include('head.php');

	$student1_id = $_GET['student1'];
	//Maak een getStudent object aan
	$getStudent = new GetStudent($wsdl);

	//Vraag om een lijstje van alle studenten
	$student = $getStudent->getStudent($student1_id);
	
	if(!empty($_POST['opslaan']))
	{
		$student1_id = $student->getId();
		$student2 = getStudentFromStudenNr($_POST['student2']);
		$docent = getDocentFromStamNr($_POST['docent']);
		
		$docent_id = '';
		
		if($docent != NULL)
		{
			$docent_id = $docent->getId();
		}
		
		$student2_id = '';
		
		if($student2 != NULL)
		{
			$student2_id = $student2->getId();
		}
		
		//Maak een nieuw stage object aan
		$newStage = new Stage($wsdl);
		
		//Set alle InitData van het stage object
		$newStage->setData($_POST['van'], $_POST['tot'], $student1_id, $student2_id, $docent_id, $_POST['bedrijfsbegeleider'], $_POST['type']);
		
		//Sla de contact op
		$result = $newStage->save();
		
		//Handel het resultaat af
		if($result=="Invalid Login")
		{
			$info = '<div class="error">'.$result.'.</div>';
		}
		else
		{
			$info = '<div class="ok">De stage is toegevoegd.</div>';
		}
	}
	
	//Kijk of er is ingelogd
	if(!isset($_SESSION['session']))
	{
		header('Location: ../');
	}
?>

<body>

    <div class="wrapper">
    	<div class="header"><img src="../img/logo.gif" /></div>
        <?php include('logininfo.php') ?>
        <div class="menu"><?php include('menu.php'); ?></div>
		<div class="sidebar">

			<?php include('../copyrightBox.php') ?>

		</div>
        
    	<div class="content">
        	<script type="text/javascript"> 
				window.addEvent('domready', function()
				{
 					$$('input.DatePicker').each(function(el)
					{
						new DatePicker(el);
					});
					
					new FormCheck('stage');
 
					new Autocompleter.Request.JSON('word', '../functions/util/query_begeleiders.php', {
						'postVar': 'word'
					});
 				});
			</script>

        	<h3 class="header">Stage Toevoegen</h3>
            <form method="post" id="stage">
            <b>Student 1</b>
            <br /><? echo($student->getFullName()); ?>
            <br />
            <br /><b>Student 2</b>
            <br /><input type="text" name="student2" size="30" />
            <br /><br /><b>Van*</b>
            <br /><input type="text" name="van" size="30" class="DatePicker" tabindex="1" value="<?php  echo date("d/m/Y"); ?>" alt="{format:'dd/mm/yyyy'}" />
			<br /><b>Tot*</b>
            <br /><input type="text" name="tot" size="30" class="DatePicker" tabindex="1" value="<?php  echo date("d/m/Y", strtotime('+ 6 months')); ?>" alt="{format:'dd/mm/yyyy'}" />
            <br /><b>Docent*</b>
            <br />
            <input type="text" name="docent" class="validate['required']" size="30"/>
            <br /><br /><b>Bedrijfsbegeleider*</b>
            <br />
            <input type="text" name="word" class="text" id="word" />
            <br /><br /><b>Type*</b>
            <br />
            <select name="type">
            	<option>Stage</option>
                <option>Afstudeerstage</option>
            </select>
            <br /><br /><input type="submit" name="opslaan" onClick="" value="Opslaan" />
            </form>

			<?php
			if(!empty($info))
				echo($info);
			?>
			<br />><a href="student_overzicht.php">Terug naar overzicht</a>
        </div>
    </div>
</body>
</html>